// 本文件定义交易函数

package core

import (
    "common"
)

// 企业向中心机构购买原材料
func BuyMeterial(country *common.Country, company *common.Company)  {
    // 查询原材料单价
    unitPrice := country.MaterialPrice

    // 企业购买原材料结算
    company.Money -= unitPrice
    company.MaterialNum += 1

    // 中心机构出售原材料结算
    country.Money += unitPrice
    country.MaterialNum -= 1

    // 记账
    var record common.Record
    record.Buyer = "公司"
    record.Seller = "国家"
    record.Content = "主板"
    record.Num = 1
    record.Amount = unitPrice
    common.Book1 = append(common.Book1, record)
}

// 企业生产商品，生产的过程中会给员工发工资
func Produce(company *common.Company, person *common.Person)  {
    // 使用原材料生产商品，并给员工发工资
    salary := company.EmployeeSalary
    company.MaterialNum -= 1
    company.PcNum += 1
    company.Money -= salary

    // 员工接收工资
    person.Money += salary

    // 记账
    var record common.Record
    record.Buyer = "公司"
    record.Seller = "员工"
    record.Content = "工资"
    record.Num = 1
    record.Amount = salary
    common.Book1 = append(common.Book1, record)
}

// 公民购买一次商品
func Consume(person *common.Person, company *common.Company)  {
    // 查询商品价格
    price := company.PcPrice

    // 购买商品
    person.Money -= price
    person.PcNum += 1
    company.PcNum -= 1
    company.Money += price

    // 记账
    var record common.Record
    record.Buyer = "公民"
    record.Seller = "公司"
    record.Content = "电脑"
    record.Num = 1
    record.Amount = price
    common.Book1 = append(common.Book1, record)
}
